      ! Returns the previous concentration in the array (taking boundary conditions into
      ! account)
      subroutine get_last_val(last_x, x, i, n)
          implicit none;
          INTEGER, INTENT(in) :: i, n;
          DOUBLE PRECISION, INTENT(inout) :: last_x;
          DOUBLE PRECISION :: next_x;
          DOUBLE PRECISION, DIMENSION(n) :: x;

          IF (i == 1) THEN
              last_x = 1.0; ! Constant influx
          ELSE IF (i == n) THEN
              last_x = x(i-1);
          ELSE
              last_x = x(i-1);
          END IF

          CALL get_next_val(next_x, x, i, n)
          last_x = next_x

      END SUBROUTINE get_last_val

